package com.xunwulian.dubbo.service;

import com.xunwulian.base.constant.RoleType;
import com.xunwulian.base.dao.RoleDao;
import com.xunwulian.base.entity.Role;
import com.xunwulian.base.util.EnumUtils;
import org.apache.http.util.Asserts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2017/3/13.
 */
@Service
public class InnerRoleService {

    @Autowired
    private RoleDao roleDao;

    public InnerRoleService() {
    }

    public RoleType getRoleTypeById(String roleId) {

        Role role = roleDao.getRoleById(roleId);

        Asserts.notNull(role, "role is null");

        // 向上查找角色
        while (role != null && !RoleType.SYSTEM.getType().equals(role.getPARENT_ID())) {
            role = roleDao.getRoleById(role.getPARENT_ID());
        }

        return EnumUtils.getEnumByType(RoleType.class, role.getROLE_ID());
    }

}
